package com.hhhn.wk.main.tab4;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.hhhn.wk.R;
import com.hhhn.wk.base.BaseActivity;
import com.hhhn.wk.utils.AllPublic;

import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;
/**
 * * * * * * * * * * * *
 * @author：文珂    ｡◕‿◕｡ *
 * Data：2018/1/7 0007    ｡◕‿◕｡ *
 * Function：      ｡◕‿◕｡ *
 * 意见反馈
 * * * * * * * * * * * */
public class CoupleBackActivity extends BaseActivity {
    private TextView tv_title;//标题
    private EditText mEditText;
    private Button btn_ok;
    private BaseActivity activity;
    @Override
    protected void setOnCreateContentView() {
        setContentView(R.layout.activity_couple_back);
        activity=this;
    }
    @Override
    protected void initView() {
        mEditText=findViewById(R.id.mEditText);
        tv_title=findViewById(R.id.tv_title);
        btn_ok=findViewById(R.id.btn_ok);
    }
    @Override
    protected void initData() {
        tv_title.setText("意见反馈");
    }
    @Override
    protected void initClick() {
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String trim = mEditText.getText().toString().trim();
                if (trim==null||"".equals(trim)){
                    toastWk("请输入反馈信息再提交");
                    return;
                }
                if (trim.length()>500){
                    toastWk("反馈信息最多500字");
                    return;
                }
                getJSON();
            }
        });
    }
    //提交意见
    public void getJSON() {
        showLoad();
        RequestParams params = AllPublic.getParamsAccount(activity, "/userFeedback", false);
        params.addParameter("id",getUser().getUid());/*用户Id*/
        params.addParameter("feedback",mEditText.getText().toString().trim());//
        Log.d("提交意见", "getJSON: "+params);
        //请求
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override  //成功
            public void onSuccess(String result) {
                Log.d("提交意见：", result);
                try {
                    JSONObject jsonObject= new JSONObject(result);
                    String reason = jsonObject.getString("code");
                    if (reason.equals("0")) {
                        toastWk("反馈成功");
                        finish();
                    }else {
                        toastWk(jsonObject.getString(getResources().getString(R.string.errMsg)));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dismissLoad();
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                ex.printStackTrace();
                dismissLoad();
            }
            @Override
            public void onCancelled(CancelledException cex) {
                dismissLoad();
            }
            @Override
            public void onFinished() {
                dismissLoad();
            }
        });
    }
}
